// 这是预约信息接口
import axios, { AxiosDefaultTypes } from '@/utils/axios'

import type { AxiosResponse } from 'axios'
import type { AxiosAppointmentInfoTypes } from './types'

export * from './types'

// 获取预约信息列表
/**
 *
 * @param limit 请求数据个数
 * @param skip 请求数据偏移量
 */
export const getSubscribeList: (
  limit: number,
  skip: number
) => Promise<
  AxiosResponse<AxiosDefaultTypes<AxiosAppointmentInfoTypes>, any>
> = (limit: number, skip: number) => {
  return axios.get<AxiosDefaultTypes<AxiosAppointmentInfoTypes>>(
    '/api/appointment/gain',
    {
      params: {
        limit,
        skip
      }
    }
  )
}

// 搜索预约信息列表
/**
 *
 * @param Tips 传入一个对象形式值，参数如下
 * @param1 name 姓名关键字
 * @param2 phone 手机号关键字
 * @param3 email 邮箱关键字
 * @param4 startTime 预约开始时间
 * @param5 endTime 预约终止时间
 * @param6 resule 预约状态
 * @returns 预约列表
 */
export const subscribeList: ({
  name,
  phone,
  email,
  startTime,
  endTime,
  resule,
  limit,
  skip
}: {
  name: string
  phone: string
  email: string
  startTime: number
  endTime: number
  resule: number
  limit: number
  skip: number
}) => Promise<
  AxiosResponse<AxiosDefaultTypes<AxiosAppointmentInfoTypes>, any>
> = ({ name, phone, email, startTime, endTime, resule, limit, skip }) => {
  return axios.get<AxiosDefaultTypes<AxiosAppointmentInfoTypes>>(
    '/api/appointment/search',
    {
      params: {
        name,
        phone,
        email,
        startTime,
        endTime,
        resule,
        limit,
        skip
      }
    }
  )
}

// 处理预约进度
/**
 *
 * @param appointmentID 预约消息ID
 * @param type 要改变进度的状态 1 通过  2 拒绝
 */
export const handleSchedule: (
  appointmentID: string,
  type: number
) => Promise<AxiosResponse<AxiosDefaultTypes<null>, any>> = (
  appointmentID: string,
  type: number
) => {
  return axios.post<AxiosDefaultTypes<null>>(
    '/api/appointment/handleSchedule',
    {
      appointmentID,
      type
    }
  )
}

// 删除预约记录
/**
 *
 * @param appointmentID 预约消息ID
 */
export const deleteSubscribe: (
  appointmentID: string
) => Promise<AxiosResponse<any, any>> = (appointmentID: string) => {
  return axios.post('/api/appointment/delete', {
    appointmentID
  })
}
